//
//  ControllViewController.m
//  penzer
//
//  Created by caiyc on 2018/10/2.
//  Copyright © 2018年 caiyc. All rights reserved.
//

#import "ControllViewController.h"
#import "SGPagingView.h"
#import "SGPageContentCollectionView.h"
#import "Index_LiveViewController.h"
#import "Index_Live_ListViewController.h"
#import "TodayLiveViewController.h"
#import "InvitionViewController.h"
@interface ControllViewController ()<SGPageTitleViewDelegate, SGPageContentCollectionViewDelegate,SGPageContentScrollViewDelegate>
@property (nonatomic, strong) SGPageTitleView *pageTitleView;
@property (nonatomic, strong) SGPageContentCollectionView *pageContentCollectionView;
@end

@implementation ControllViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupPageView];
    // Do any additional setup after loading the view from its nib.
}
- (void)setupPageView {

    CGFloat statusHeight = CGRectGetHeight([UIApplication sharedApplication].statusBarFrame);
    CGFloat pageTitleViewY = 0;
    
    if (statusHeight == 20.0) {
        pageTitleViewY = 64;
    } else {
        pageTitleViewY = 88;
    }
    // pageTitleViewY += self.Top_View.frame.size.height;
    
    NSArray *titleArr = @[@"今日任务", @"邀请"];
    SGPageTitleViewConfigure *configure = [SGPageTitleViewConfigure pageTitleViewConfigure];
    configure.titleColor = [UIColor blackColor];
    configure.titleFont = [UIFont fontWithName:@"Helvetica-Bold" size:18];
    configure.titleSelectedColor = [UIColor blackColor];
    configure.indicatorColor = [UIColor blackColor];
    configure.badgeSize = 15;
    //    configure.indicatorColor = [UIColor blackColor];
    //  configure.indicatorAdditionalWidth = 80; // 说明：指示器额外增加的宽度，不设置，指示器宽度为标题文字宽度；若设置无限大，则指示器宽度为按钮宽度
   // configure.titleGradientEffect = YES;
    
    /// pageTitleView
    self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(10, 45, screen_width-20, 50) delegate:self titleNames:titleArr configure:configure];
    self.pageTitleView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_pageTitleView];
    
  //  [self.pageTitleView addBadgeForIndex:0 andnum:5];
  //  [self.pageTitleView addBadgeForIndex:0];
    TodayLiveViewController *vc1 = [[TodayLiveViewController alloc]init];
    vc1.reloadBage=^(NSInteger num){
        if(num==0){
            [self.pageTitleView removeBadgeForIndex:0];
        }else
        [self.pageTitleView addBadgeForIndex:0 andnum:num];
    };
    vc1.view.backgroundColor = [UIColor clearColor];
    InvitionViewController *vc2 = [[InvitionViewController alloc]init];
    vc2.reloadBage = ^(NSInteger num) {
        if(num==0){
            [self.pageTitleView removeBadgeForIndex:1];
        }else
         [self.pageTitleView addBadgeForIndex:1 andnum:num];
    };
    NSArray *childArr = @[vc1,vc2];;
    /// pageContentCollectionView
    CGFloat ContentCollectionViewHeight = screen_height - CGRectGetMaxY(_pageTitleView.frame)-80;//内嵌的子控制器的视图高度
    self.pageContentCollectionView = [[SGPageContentCollectionView alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(_pageTitleView.frame)+10, screen_width-20, ContentCollectionViewHeight) parentVC:self childVCs:childArr];
    _pageContentCollectionView.delegatePageContentCollectionView = self;
    _pageContentCollectionView.layer.cornerRadius = 5;
    _pageContentCollectionView.layer.masksToBounds = 1;
   // _pageContentCollectionView.backgroundColor = [UIColor redColor];
    
    //_pageContentCollectionView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_pageContentCollectionView];

}
- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
    [self.pageContentCollectionView setPageContentCollectionViewCurrentIndex:selectedIndex];
}

- (void)pageContentCollectionView:(SGPageContentCollectionView *)pageContentCollectionView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex {
    [self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];
}
//- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
//    [self.pageContentScrollView setPageContentScrollViewCurrentIndex:selectedIndex];
//}
//
//- (void)pageContentScrollView:(SGPageContentScrollView *)pageContentScrollView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex {
//    [self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];
////}
//- (void)pageContentScrollViewWillBeginDragging {
//    _pageTitleView.userInteractionEnabled = NO;
//}
//
//- (void)pageContentScrollViewDidEndDecelerating {
//    _pageTitleView.userInteractionEnabled = YES;
//}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
